/*
* (C) Copyright 2013 Philip Kirchhoff 
* 
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*-------------------------------------------------------------------------------
* This file is part of the DataLogger library by Philip Kirchhoff
* https://code.google.com/p/pk-data-logger/
* SVN: http://pk-data-logger.googlecode.com/svn/trunk
*-------------------------------------------------------------------------------
* Module    : DlBoolChannel.cpp   
* Author    : Kirchhoff, Philip
* Date      : 01.04.2013
*-------------------------------------------------------------------------------
* Function definitions for class DlBoolChannel
*   
*-------------------------------------------------------------------------------
* Change History:
* 01.04.2013  Kirchhoff 	Created
--------------------------------------------------------------------------------
*/

#include <stdexcept>

#include "DlBoolChannel.h"

using namespace std;

/**************************************************************************//**
* @brief Constructs an empty status channel with number, ID and normal state
* @param channelNum Channel number
* @param channelId ID of the channel
* @param normalState Normal state of the channel
******************************************************************************/
DlBoolChannel::DlBoolChannel(unsigned int channelNum, string channelId,
                             string channelUnit, string channelDescr)
    : DlDataChannel(TYPE_BOOL, channelNum, channelId, channelUnit, channelDescr)
{

}

/**************************************************************************//**
* @brief Destructor
******************************************************************************/
DlBoolChannel::~DlBoolChannel()
{

}

/**************************************************************************//**
* @brief Gets the number of stored samples
* @return Number of samples
******************************************************************************/
unsigned int DlBoolChannel::numSamples()
{
    return mData.size();
}

/**************************************************************************//**
* @brief Get a sample
* @param sampleNum Sample number
* @return Sample value
* \details Please note that an std::runtime_error will be thrown if no data
*			was set. If sampleNum exceeds the number of stored damples an
*			std::range_error will be thrown
******************************************************************************/
bool DlBoolChannel::sample(unsigned int sampleNum)
{
    if(sampleNum >= mData.size())
    {
        std::string excString(__PRETTY_FUNCTION__);
        excString += ": Sample number exceeds number of stored samples!";
        throw std::runtime_error(excString.c_str());
    }
    return mData[sampleNum];
}

/**************************************************************************//**
* @brief Get a string-converted sample
* @param sampleNum Sample number
* @return Sample value string
******************************************************************************/
std::string DlBoolChannel::sampleString(unsigned int sampleNum)
{
    if(sample(sampleNum))
        return "1";
    else
        return "0";
}
